<?php

namespace app\selladmin\model;

use think\Model;
use think\Db;
use app\selladmin\model\Order;
use app\selladmin\model\Custom;

/*
 * 订单
 */

class CtmStaff extends Model {

    const STATUS_1 = 1; //待服务
    const STATUS_2 = 2; //服务中
    const STATUS_3 = 3; //已完成
    const STATUS_4 = 4; //已取消

    //预约对应的客户

    public function Custom() {
        return $this->hasOne('Custom', 'id', 'ctm_id')->field('id,custom_name,real_name,custom_phone');
    }

    //预约对应的美容师
    public function Staff() {
        return $this->hasOne('Staff', 'id', 'staff_id')->field('id,staff_name');
    }

    //预约对应的项目信息
    public function Item() {
        return $this->hasOne('Item', 'id', 'item_id')->field('id,item_name');
    }

    //查询预约信息
    public function OnlineInfo($ctm_id, $store_id, $ordid, $pagenum) {
        if ($ordid) {
            $onlinewhere['order_id'] = $ordid;
        }
        if ($ctm_id) {
            $onlinewhere['ctm_id'] = $ctm_id;
        }
        if ($store_id) {
            $onlinewhere['store_id'] = $store_id;
            $p['store_id'] = $store_id;
            $p['id'] = $store_id;
        } else {
            $p = [];
        }
        $onlinewhere = isset($onlinewhere) ? $onlinewhere : [];
        $onlineList = CtmStaff::with('Custom,Staff,Item')
                ->where($onlinewhere)
                ->field("id,staff_id,ctm_id,item_id,status,start_time,add_time,store_id")
                ->order("add_time desc")
                ->paginate($pagenum, false, ['var_page' => 'page5', 'fragment' => 'online'])
                ->appends($p);
        return $onlineList;
    }

}
